﻿@using Webdiyer.WebControls.Mvc
@using HiLand.General.Entity
@using HiLand.Utility4.MVC
@using HiLand.General
@using HiLand.Utility4.MVC.Data
@model PagedList<SimpleProductEntity>
@{
    ViewBag.Title = "产品列表";
}
<style type="text/css">
    .modalFix
    {
        width: 650px;
    }
</style>
<h2>
    产品列表</h2>
<div id="ItemListDIV">
    <div class="OperateArea" id="OperateAreaContainer">
        <a href="#" id="NewDisplayA" class="modalInput" rel="#ProductDisplayDIV">新建</a>
    </div>
    <table width="98%" class="grid">
        <tr>
            <th style="width: 150px">
                操作
            </th>
            <th style="width: 80px">
                产品名称
            </th>
            <th style="width: 80px">
                产品编号
            </th>
            <th style="width: 80px">
                类别名称
            </th>
            <th style="width: 60px">
                价格
            </th>
            <th style="width: 60px">
                促销价格
            </th>
            <th style="width: 60px">
                市场参考价格
            </th>
            <th>
                是否可用
            </th>
            <th>
                首页显示
            </th>
        </tr>
        @foreach (SimpleProductEntity entity in Model)
        {
            <tr>
                <td>
                    <a href="#" class="modalInput editItme" rel="#ProductDisplayDIV" itemGuid="@entity.ProductGuid">编辑</a> | <a href="#" class="deleteItme"  itemGuid="@entity.ProductGuid">
                        删除</a> | <a href="#" class="pictureItme"  itemGuid="@entity.ProductGuid">图片</a>
                </td>
                <td>@entity.ProductName
                </td>
                <td>@entity.ProductCode
                </td>
                <td>@entity.ProductCategoryName
                </td>
                <td>@entity.ProductPriceNormal
                </td>
                <td>@entity.ProductPricePromotion
                </td>
                <td>@entity.ProductPriceReference
                </td>
                <td>
                    @entity.CanUsable.ToString()
                </td>
                <td>
                    @entity.ProductIsTop.ToString()
                </td>
            </tr>   
        }
    </table>
    <div class="modal modalFix" id="ProductDisplayDIV">
    </div>


    @Html.Pager(Model, new PagerOptions() { PageIndexParameterName = "id", ShowDisabledPagerItems = false, AlwaysShowFirstLastPageNumber = true })
    <script type="text/javascript">
        $(document).ready(function () {
            $(".modalInput").overlay({
                mask: {
                    color: '#ebecff',
                    loadSpeed: 200,
                    opacity: 0.9
                },
                closeOnClick: false
            });

            var productDetailsUrl = '@Url.Action("ProductDetails")';
            var imageListUrl = '@Url.Action("ImageList", "Image")'
            var returnUrl = window.location;

            $("#NewDisplayA").click(function () {
                $("#ProductDisplayDIV").load(productDetailsUrl + "?returnUrl=" + returnUrl + "&r=" + Math.random());
            });

            $(".editItme").click(function () {
                var itemGuid = $(this).attr("itemGuid");
                $("#ProductDisplayDIV").load(productDetailsUrl + "?productGuid=" + itemGuid + "&returnUrl=" + returnUrl + "&r=" + Math.random());
            });

            $(".pictureItme").click(function () {
                var itemGuid = $(this).attr("itemGuid");

                var targetUrl = $.UrlUtil(imageListUrl).concat("returnUrl", returnUrl).concat("productGuid", itemGuid).show(true);
                window.location = targetUrl;
            });

            $("a.deleteItme").click(function () {
                var result = confirm("need delete this record?");
                if (result == true) {
                    var targetID = $(this).attr("itemGuid");
                    var url = '@Url.Action("ProductDelete")';
                    $.post(url, { productGuid: targetID }, function (data) {
                        if (data.IsSuccessful == true) {
                            window.location.reload();
                        }
                        else {
                            alert("delete failure!");
                        }
                    });
                }
            });
        });
    </script>
</div>
